package chapter13.h13_2;

import chapter13.Directory;
import chapter13.Entry;
import chapter13.File;
import chapter13.Visitor;

import java.util.Iterator;

public class SizeVisitor extends Visitor {
    private int size = 0;
    @Override
    public void visit(File file) {
        size += file.getSize();
    }

    @Override
    public void visit(Directory directory) {
        Iterator<Entry> it = directory.iterator();
        while(it.hasNext()){
            Entry entry = it.next();
            entry.accept(this);
        }
    }
    public int getSize(){
        return size;
    }
}
